﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="UsersForCustomers.aspx.cs" Inherits="FimetContoDeposito.Anagrafiche.UsersForCustomers" %>

<%@ Register assembly="GrayParrot.Web.Controls" namespace="GrayParrot.Web.Controls" tagprefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <asp:PlaceHolder ID="PlaceHolder1" runat="server">        
        <%: Styles.Render("~/bundles/Datatables/css") %>
        <%: Scripts.Render("~/bundles/Datatables") %>
    </asp:PlaceHolder>

    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.Core.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.DataTables.js"></script> 
    <script type="text/javascript" lang="javascript" src="../Scripts/GrayParrot.Modals.js"></script> 
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <!-- 
        Sitemap Menu item:
        <siteMapNode url="~/UsersForCustomers.aspx" title="UsersForCustomers" description="UsersForCustomers" image="fa-laptop" id="UsersForCustomers"/>
    -->
    <section class="panel">
	    <header class="panel-heading">
			<b>Anagrafica Operatori</b>
		</header>
        
        <a class="collapsed" data-toggle="collapse" href="#collapseSetting">
            <h4 class="fa  fa-search"> Filters</h4>
        </a>
        <section id="collapseSetting" class="collapse" style="height: 0px;">
            <div class="collapse-boby" style="padding:0">
                <% HttpContext.Current.Response.Write(this.JQDTable.RenderExternalFilters()); %>
            </div>
        </section>

		<div class="panel-body">

            <!-- PUT YOUR CONTENT HERE -->
            <iframe id='iframeCrud' frameborder="0" style="width:800px; height:500px; display:none"></iframe>
            <div id="crudDialog" title="" style="display:none"></div>
            <div id="deleteDiv" title="" style="display:none"></div>

            <cc1:JQDataTable ID="JQDTable" runat="server" 
                    SelectionMode="Single" 
                    RenderScripts="false" 
                    BootstrapClasses="table table-hover table-bordered table-condensed">
                <FeaturesConfig>
                    <Features>
                        <cc1:Searching Value="Both" ExternalFilters="true">
                            <Filters>
                                <cc1:TextColumnFilter ColumnName="Nome" />
                                <cc1:TextColumnFilter ColumnName="Cognome" />
                                <cc1:TextColumnFilter ColumnName="Username" />
                                <cc1:TextColumnFilter ColumnName="Email" />
                                <cc1:SelectColumnFilter ColumnName="Azienda" 
                                                        SelectType="Simple" Url="/api/Common/LoadCustomersDDL"
                                                        IdProp="value" TextProp="name" Width="400"
                                                        MinimumInputLength="2" />
                            </Filters>
                        </cc1:Searching>
                        <cc1:AutoWitdh Value="true" />
                        <cc1:ScrollY Value="500" ScrollCollapse="true" />
                        <cc1:LengthChange Value="false" />
                        <cc1:Paging PagingType="FullNumbers" PageLength="20" />
                    </Features>
                </FeaturesConfig>
                <ControllerConfig Url="/api/Customers/LoadCustomerOperatorBags" LoadingMode="OnLoad">
                </ControllerConfig>
                <ColumnsConfig Key="Id">
                    <Columns>
                        <cc1:TextColumn Name="Id" Header="Id" Visible="false" />
                        <cc1:TextColumn Name="Nome" Header="Nome" />
                        <cc1:TextColumn Name="Cognome" Header="Cognome" />
                        <cc1:TextColumn Name="Username" Header="Username" />
                        <cc1:TextColumn Name="Email" Header="Email" />
                        <cc1:TextColumn Name="Azienda" Header="Azienda" />
                        <cc1:BooleanColumn Name="IsApprovato" Header="Approvato" Width="20px" />
                        <cc1:TextColumn Name="Note" Header="Note" />
                        <cc1:ActionColumn >
                            <Actions>
                                <cc1:ActionIcon Icon="fa fa-pencil" Callback="EditCallback" />
                                <cc1:ActionIcon Icon="fa fa-trash-o" Callback="DeleteCallback" />
                                <cc1:ActionIcon Icon="fa fa-envelope-o" Callback="ConfirmRegistrationCallback" />
                            </Actions>
                        </cc1:ActionColumn>
                    </Columns>
                </ColumnsConfig>
                <Toolbar>
                    <cc1:IconButton Icon="fa-plus" Callback="LoadAddDialog" />
                </Toolbar>
<%--                <Buttons>
                    <cc1:CrudAddButton Text="Aggiungi" Callback="LoadAddDialog" />
                    <cc1:CrudEditButton Text="Modifica" Callback="LoadEditDialog" />
                    <cc1:CrudDeleteButton Text="Cancella" Callback="DeleteDialog" />
                </Buttons>--%>
            </cc1:JQDataTable>

		</div>
	</section>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="LocaJavascript" runat="server">
    <% HttpContext.Current.Response.Write(this.JQDTable.RenderScriptsManually()); %>

<script>
    function CloseDialog(response) {
        $('#crudDialog').dialog('close');

        ShowResponseMessage(response);
    }

    function LoadAddDialog() {

        $("#iframeCrud").prop('src', 'UsersForCustomers_CRUD.aspx').appendTo("#crudDialog");
        $("#iframeCrud").show();

        m_dialog = $("#crudDialog").dialog({
            title: 'Nuovo Operatore',
            width: 'auto',
            height: 'auto',
            modal: true,
            close: function () {
                RedrawGrid(m_tableJQDTable);

                $("#iframeCrud").contents().remove();
                $('#iframeCrud').hide();
            }
        });
    }

    function LoadEditDialog() {

        var p = null;

        p = GetSelectedData(m_tableJQDTable).Id;

        var url = 'UsersForCustomers_CRUD.aspx?id=' + p;

        $("#iframeCrud").prop('src', url).appendTo("#crudDialog");
        $("#iframeCrud").show();

        m_dialog = $("#crudDialog").dialog({
            title: 'Modifica Opeartore',
            width: 'auto',
            height: 'auto',
            modal: true,
            close: function () {
                RedrawGrid(m_tableJQDTable);

                $("#iframeCrud").contents().remove();
                $('#iframeCrud').hide();
            }
        });
    }

    function DeleteDialog() {
        var p = null;

        var row = GetSelectedData(m_tableJQDTable);

        p = row.Id;

        var url = '/api/Customers/DeleteCustomerOperatorBags';

        $("#crudDialog").html("Confermi la cancellazione dell'elemento con codice: " + p + " ?");

        // Define the Dialog and its properties.
        $("#crudDialog").dialog({
            resizable: false,
            modal: true,
            title: "Cancella Operatore",
            height: 250,
            width: 400,
            buttons:[
                {
                    id: "Yes",
                    text: "Si",
                    click: function () {
                        $(this).dialog("option", { buttons: {} });
                        //$(this).empty();
                        $(this).dialog('close');

                        $.ajax({
                            type: "POST",
                            url: url,
                            data: JSON.stringify({ id: p }),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (response) {
                                RedrawGrid(m_tableJQDTable);

                                $("#crudDialog").empty();

                                alert(response);
                            },
                            failure: function (response) {

                                $("#crudDialog").empty();

                                alert(response);
                            }
                        });
                    }
                },
                {
                    id: "No",
                    text: "No",
                    click: function () {
                        $("#crudDialog").empty();

                        $(this).dialog('close');
                    }
                }
            ]
        });
    }

    function ConfirmRegistrationCallback(obj) {
        var p = null;
        p = obj.Id;

        var url = '/api/Customers/ConfirmRegistration';

        $.ajax({
            type: "POST",
            url: url,
            data: JSON.stringify({ id: p }),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                //$("#crudDialog").html('');
                $("#deleteDiv").contents().remove();
                $('#deleteDiv').hide();

                alert(response);
            },
            failure: function (response) {

                //$("#crudDialog").empty();
                $("#deleteDiv").contents().remove();
                $('#deleteDiv').hide();

                alert(response);
            }
        });
    }

    function EditCallback(obj) {
        var p = null;
        p = obj.Id;

        var url = 'UsersForCustomers_CRUD.aspx?id=' + p;

        $("#iframeCrud").prop('src', url).appendTo("#crudDialog");
        $("#iframeCrud").show();

        m_dialog = $("#crudDialog").dialog({
            title: 'Anagrafica Operatore',
            width: 'auto',
            height: 'auto',
            modal: true,
            close: function () {
                RedrawGrid(m_tableJQDTable);

                $("#iframeCrud").contents().remove();
                $('#iframeCrud').hide();
            }
        });
    }

    function DeleteCallback(obj) {
        var p = null;
        p = obj.Id;

        var url = '/api/Customers/DeleteCustomerOperatorBags';

        $("#deleteDiv").contents().remove();
        $("#deleteDiv").html("Confermi la cancellazione dell'operatore: " + obj.Nome + " " + obj.Cognome + " ?").appendTo("#crudDialog");
        //$("#crudDialog").html("Confermi la cancellazione dell'elemento con codice: " + p + " ?");
        $("#deleteDiv").show();

        // Define the Dialog and its properties.
        $("#crudDialog").dialog({
            resizable: false,
            modal: true,
            title: "Cancella Operatore",
            height: 250,
            width: 400,
            buttons:[
                {
                    id: "Yes",
                    text: "Si",
                    click: function () {
                        $(this).dialog("option", { buttons: {} });
                        //$(this).empty();
                        $(this).dialog('close');

                        $.ajax({
                            type: "POST",
                            url: url,
                            data: JSON.stringify({ id: p }),
                            contentType: "application/json; charset=utf-8",
                            dataType: "json",
                            success: function (response) {
                                RedrawGrid(m_tableJQDTable);

                                //$("#crudDialog").html('');
                                $("#deleteDiv").contents().remove();
                                $('#deleteDiv').hide();

                                alert(response);
                            },
                            failure: function (response) {

                                //$("#crudDialog").empty();
                                $("#deleteDiv").contents().remove();
                                $('#deleteDiv').hide();

                                alert(response);
                            }
                        });
                    }
                },
                {
                    id: "No",
                    text: "No",
                    click: function () {
                        //$("#crudDialog").empty();
                        $("#deleteDiv").contents().remove();
                        $('#deleteDiv').hide();

                        $(this).dialog('close');
                    }
                }
            ]
        });
    }
</script>
</asp:Content>